import java.io.File;

/**
 * @ClassName copyDownload
 * @Author Alex2
 * @Date 2025/3/6 18:08
 * @Description 将Edge浏览器下载的视频提取到另一个文件夹中
 **/
public class copyDownload {
    public static void main(String[] args) {
        File sourceDir = new File("C:/Users/Alex2/Desktop/source");
        File targetDir = new File("C:/Users/Alex2/Desktop/target");
//        copyDirectory1(sourceDir, targetDir);   //含外部UUID文件夹
        copyDirectory2(sourceDir, targetDir);   //不含外部UUID文件夹
    }

    /**
     * @Author: Alex
     * @Description: 含外部UUID文件夹
     */
    public static void copyDirectory1(File sourceFile, File targetFile) {
        File[] files = sourceFile.listFiles();
        if (files == null) {
            System.out.println("文件夹为空");
        } else {
            for (File file : files) {
                if (file.isDirectory()) {
                    File[] child = file.listFiles();
                    if (child != null) {
                        for (File childFile : child) {
                            String sourceUrl = childFile.toString();
                            String targetUrl = targetFile.toString() + File.separator + sourceUrl.substring(sourceUrl.lastIndexOf("P"));
                            System.out.println(sourceUrl + " -> " + targetUrl);
                            File target = new File(targetUrl);
                            copySingleFile.copyFile(childFile, target);
                        }
                    }
                }
            }
            System.out.println("提取成功");
        }
    }

    /**
     * @Author: Alex
     * @Description: 不含外部UUID文件夹
     */
    public static void copyDirectory2(File sourceFile, File targetFile) {
        File[] files = sourceFile.listFiles();
        if (files == null) {
            System.out.println("文件夹为空");
        } else {
            for (File file : files) {
                String sourceUrl = file.toString();
                String targetUrl = targetFile.toString() + File.separator + sourceUrl.substring(sourceUrl.lastIndexOf("P"));
                System.out.println(sourceUrl + " -> " + targetUrl);
                File target = new File(targetUrl);
                copySingleFile.copyFile(file, target);
            }
            System.out.println("提取成功");
        }
    }
}